﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Data.SqlClient;

/// <summary>
/// Summary description for DA_Bonus
/// </summary>
/// 
namespace Bestlife.ERP.DataAccess
{
    public class DA_Bonus
    {
        public DA_Bonus()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Boolean Bonus_Add(Entities.E_Bonus E_eb) 
        {
            bool ExProduct = false;

            try
            {
                String connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
                Bestlife.ERP.DataAccess.clsCon.connect(connStr);

                String insertBonus = "INSERT INTO Bonus(User_id,Tpv,ppv,Cpv,T_sales,T_commision,Subdealers_Id,Bv,user_Status,Tbv)VALUES('" + E_eb.User_id + "','" + E_eb.Tbv + "','" + E_eb.Ppv + "','" + E_eb.Cpv + "','" + E_eb.T_sales + "','" + E_eb.T_commision + "','" + E_eb.Subdealers_Id + "','" + E_eb.Bv + "','" + E_eb.User_Status + "','" + E_eb.Tbv + "')";
                ExProduct = Bestlife.ERP.DataAccess.clsCon.AddEditDel(insertBonus);
               
               
            }
            catch (Exception ee) 
            {
            }

            return ExProduct;
        }


        public static Entities.E_Bonus Getbonus(String uid)
        {
            Entities.E_Bonus Getbns=null;
            try
            {//try

                String connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
                Bestlife.ERP.DataAccess.clsCon.connect(connStr);


                String sqlstatus = "SELECT * from Bonus where User_id='" + uid + "'";
                SqlDataReader rdRStatus;
                rdRStatus = clsCon.ReadTable(sqlstatus);


                if (rdRStatus.Read())
                {
                    Getbns.Tpv = decimal.Parse(rdRStatus["Tpv"].ToString());
                    Getbns.Ppv = decimal.Parse(rdRStatus["ppv"].ToString());
                    Getbns.Cpv = decimal.Parse(rdRStatus["Cpv"].ToString());
                    Getbns.T_sales = decimal.Parse(rdRStatus["T_sales"].ToString());
                    Getbns.T_commision = decimal.Parse(rdRStatus["T_commision"].ToString());
                    Getbns.Subdealers_Id = rdRStatus["Subdealers_Id"].ToString();
                    Getbns.Bv = decimal.Parse(rdRStatus["Bv"].ToString());
                    Getbns.User_Status = rdRStatus["user_Status"].ToString();
                    Getbns.Tbv = decimal.Parse(rdRStatus["Tbv"].ToString());
                }


            }//try


            catch (Exception err)
            {

              
            }

            finally
            {
                clsCon.conn_new.Close();
             
            }   //finally
            return Getbns;



        }


    }
}